'use strict'

let Koa = require('koa')
let wechat = require('./wechat/g.js')
let path = require('path')
let util = require('./libs/util.js')
let wechat_file = path.join(__dirname, './config/wechat.txt')

let config = {
    wechat: {
        appId: 'wxe8ce51f0f9466bcc',
        appsecret: '06e1beb828954aa4491e2d176f5ce856',
        token: 'shiguangweiming',
        getAccessToken: function(){
            return util.readFileAsync(wechat_file)
        },
        saveAccessToken: function(data){
            data = JSON.stringify(data)
            return util.writeFileAsync(wechat_file, data)
        }
    }
}

let app = new Koa()

app.use(wechat(config.wechat))
app.listen(8082)
console.log('listen on 8082')